/**
 * ===========================================================================
 * 版权所有 湖南免了么网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.mianle.me
 * ===========================================================================
 * 11:06 2018/7/9
 */
package com.mianle.userapi.service.delayed.demo1;

import java.util.Date;
import java.util.concurrent.DelayQueue;

/**
 * @Author: yiyuan
 * @Description:
 * @Date: Created in 11:06 2018/7/9
 *
 */
public class Task implements Runnable  {

    private int id;
    private DelayQueue<Event2> delayQueue;

    public Task(int id, DelayQueue<Event2> delayQueue) {
        this.id = id;
        this.delayQueue = delayQueue;
    }

    @Override
    public void run() {
        Date nowDate = new Date();
        Date delay = new Date();
        delay.setTime(nowDate.getTime() + id * 1000);
        System.out.println("Thread " + id + " " + delay);

        for (int i = 0; i < 100; i++) {
            Event2 event2 = new Event2(delay);
            delayQueue.add(event2);
        }
    }
}
